const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const StylelintPlugin = require('stylelint-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')

module.exports = {

    entry: './src/main.js',
    module: {
        // 这里的rules里不做less和css的配置，分别在dev和pro里分别设置
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: [
                    'babel-loader',
                ]
            },
            {
                test: /\.(png|jpg|jpeg|git)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 10 * 1024,
                        esModule: false,
                    }
                }
            },
            {
                test: /\.(js|vue)$/,
                use: [
                    'eslint-loader',
                ],
                enforce: 'pre'
            },
            {
                test: /\.vue$/,
                use: [
                    'vue-loader',
                ]
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new StylelintPlugin({
            files: ['src/**.{vue,html,css,less}'],
            fix: false,
            cache: false,
            emitError: true,
            failOnError: false,
        }),
        new HtmlWebpackPlugin({
            template: './public/index.html',
            title: 'DIY webpack'
        }),
        new webpack.DefinePlugin({
            BASE_URL: '"./"'
        }),
        new FriendlyErrorsPlugin(),
    ],
    resolve: {
        extensions: ['.js', '.json', '.vue']
    }

}